/*
 * @Author: 蔡霸霸
 * @Date: 2020-05-12 10:27:16
 * @LastEditors: 蔡霸霸
 * @LastEditTime: 2020-06-13 11:17:18
 * @FilePath: \Nuxt_music\store\index.js
 */

import Vuex from 'vuex'
import { api } from './actions/api'
import { music } from './actions/music'

const getDefaultState = () => {
  return {
    userinfo: {
      profile: {
        avatarUrl: '',
        nickname: ''
      }
    },
    showNav: true,
    token: '',
    uid: '',
    avatar: '',
    name: '',
    music_list: [
      {
        name: '',
        artist: '',
        cover: '',
        source: '',
        id: ''
      }
    ],
    drawerFlag: false //* 音乐下拉框开关
  }
}

const createdStore = () => {
  return new Vuex.Store({
    strict: false,
    state: getDefaultState(),
    mutations: {
      Set_drawerFlag: (state, data) => {
        state.drawerFlag = data
      },
      Reset_State: (state) => {
        //* 初始化state
        Object.assign(state, getDefaultState())
      },
      Set_music_list: (state, arr) => {
        state.music_list = arr
      },
      set_showNav: (state, data) => {
        //* 红色背景二级导航是否显示
        state.showNav = data
      },
      set_UserInfo: (state, data) => {
        //* 设置用户信息
        state.userinfo = data
      },
      SET_AVATAR: (state, avatar) => {
        //* * 设置用户头像 */
        state.avatar = avatar
      },
      SET_NAME: (state, name) => {
        //* *设置用户姓名 */
        state.name = name
      },
      SET_TOKEN: (state, token) => {
        //* *设置token */
        state.token = token
      },
      SET_UID: (state, uid) => {
        //* *设置用uid */
        state.uid = uid
      }
    },
    actions: {
      ...api,
      ...music
    }
  })
}

export default createdStore
